﻿using Elsa.Expressions.Services;
using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Activities.Flowchart.Activities;
using Elsa.Workflows.Activities.Flowchart.Models;
using Elsa.Workflows.Management.Services;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Runtime;
using Elsa.Expressions;

namespace ElsaDemo
{
    /// <summary>
    /// Demo workflow
    /// </summary>
    public class Workflow1 : WorkflowBase
    {
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        protected override ValueTask BuildAsync(IWorkflowBuilder builder, CancellationToken cancellationToken = default)
        {
            builder.DefinitionId = $"Workflow1_001";
            builder.Name = "Workflow111";
            builder.Id = Guid.NewGuid().ToString();
            builder.Description = "This is a demo workflow.";
            var w1 = new WriteLine("Please enter your name:", "nameVariable");
            //var r1 = new ReadLine("nameVariable");
            var c1 = new CustomActivity1 { Metadata = new Dictionary<string, object> { ["Result"] = "nameVariable" } };
            var e1 = new End();
            builder.Root = new Flowchart
            {
                Activities =
                {
                    w1,c1,e1
                },
                Connections =
                {
                    new Connection(w1, c1),
                    //new Connection(r1, c1),
                    new Connection(c1, e1)
                }
            };

            return ValueTask.CompletedTask;
        }
    }

    public class Workflow2 : WorkflowBase
    {
        protected override void Build(IWorkflowBuilder builder)
        {
            builder.DefinitionId = "Workflow02";
            builder.Name = "Workflow0202";
            builder.Root = new Sequence
            {
                Activities =
                {
                    new WriteLine("Please enter your name:"),
                    new CustomActivity1 { Metadata = new Dictionary<string, object> { ["Result"] = "nameVariable" } },
                    new End()
                }
            };
        }
    }
}
